/*
 *
 * 目录
 */

import { createAPI } from '@/utils/request'
import * as URL from '../../constants/api'
// 目录列表
const formOfEmploymentMapping = new Map([
  [1, '已启用'],
  [0, '已禁用'],
  ['1', '启用'],
  [2, '禁用']
])
export const list = data => createAPI(URL.DIRECTORYS, 'get', data)
.then(res => ({
  items: res.data.items.map((p, i) => ({
    ...p,
    index: ++i,
    state: formOfEmploymentMapping.get(p.state)
  })),
  counts: res.data.counts,
  page: res.data.page,
  pages: res.data.pages,
  pagesize: res.data.pagesize
}))
.catch(() => {})
// 目录简单列表
export const simple = data => createAPI('/directorys/simple', 'get', data)

// 目录详情
export const detail = data => createAPI(`/directorys/${data.id}`, 'get', data)

// 目录添加
export const add = data => createAPI('/directorys', 'post', data)

// 目录修改
export const update = data => createAPI(`/directorys/${data.id}`, 'put', data)

// 目录删除
export const remove = data =>
  createAPI(`/directorys/${data.id}`, 'delete', data)

// 目录状态
export const changeState = data => createAPI(`/directorys/${data.id}/${data.state}`, 'post', data)
